
import { auditList, updateAudit } from "@/tools/request/api.js"
import JSONBig from 'json-bigint';
 

export default {
	namespaced: true,
	state: () => ({
		original_goods_price: 0,
		final_goods_price: 0,
		shop_cart_list: [],
		firm_rate: 1, 				//店铺折扣率 0~1
		firm_reduced_price: 0, 		// 店铺优惠后的价格
		coupon_reduced_money: 0, 	//优惠券优惠后的价格
		selectCoupon: {} 			// 当前选择的优惠券
	}),
	mutations: {
		// 设置订单原价
		SET_ORIGINAL_GOODS_PRICE (state, value) {
			state.original_goods_price = value * 1;
		},
		// 设置订单优惠后的价格
		SET_FINAL_GOODS_PRICE (state, value) {
			state.final_goods_price = value * 1;
		},
		// 设置订单商品列表
		SET_SHOP_CART_LIST (state, value) {
			state.shop_cart_list = value;
		},
		// 设置店铺优惠价
		SET_FIRM_DISCOUNT (state, rate) {
			state.firm_rate = rate * 1;
			let finalMonry = rate * state.original_goods_price;
			finalMonry = Math.round(finalMonry * 100) / 100;
			state.firm_reduced_price = finalMonry;
			this.commit('pay_store/SET_FINAL_GOODS_PRICE', finalMonry);
			console.log(finalMonry, 'finalMonry___')
		},
		// 设置优惠券的优惠价
		SET_COUPON_DISCOUNT (state, reducedMoney) {
			state.coupon_reduced_money = reducedMoney;
			this.commit('pay_store/SET_FINAL_GOODS_PRICE', reducedMoney);
		},
		// 设置当前优惠券
		SET_CURRENT_COUPON (state, coupon) {
			state.selectCoupon = coupon;
		}
		
	},
	actions: {
		
	},
	getters: {
		// 总共优惠的金额
		tootalDiscountMoney (state) {
			let discount = state.original_goods_price - state.final_goods_price;
			return discount.toFixed(2);
		},
		// 店铺优惠的金额
		firmDiscountMoney (state) {
			let discount = state.original_goods_price - state.firm_reduced_price;
			discount = Math.round(discount * 100) / 100;
			return discount.toFixed(2);
		},
		
	},
}
